/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.Excel;

import BO.Iter.SinhVienBO;
import TableModel.Sinhvien;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


/**
 *
 * @author vt
 */
public class SaveToDatabase {
    public Sinhvien sinhvien;
   // private String nameFile;
   // private String path;
    //private SinhVienBO svBO;
    
    public static long saveToDatabase(InputStream inputStream){
                POIFSFileSystem fileSystem = null;
    try
      {
                fileSystem = new POIFSFileSystem (inputStream);
                HSSFWorkbook      workBook = new HSSFWorkbook (fileSystem);
                HSSFSheet         sheet    = workBook.getSheetAt (0);
                Iterator rows     =  sheet.rowIterator ();
                  while (rows.hasNext ())
                     {
                          HSSFRow row = (HSSFRow) rows.next ();
                            // display row number in the console.
                        System.out.println ("Row No.: " + row.getRowNum ());
                              // once get a row its time to iterate through cells.
                          Iterator cells = row.cellIterator ();
                          while (cells.hasNext ())
                             {
                                    HSSFCell cell = (HSSFCell) cells.next ();
                                    System.out.println ("Cell No.: " + cell.getCellNum ());
                                    /*
                                     * Now we will get the cell type and display the values
                                     * accordingly.
                                     */
                switch (cell.getCellType ())
                {
                        case HSSFCell.CELL_TYPE_NUMERIC :
                        {
                                // cell type numeric.
                                System.out.println ("Numeric value: " + cell.getNumericCellValue ());

                                break;
                        }
                        case HSSFCell.CELL_TYPE_STRING :
                        {
                                // cell type string.
                                HSSFRichTextString richTextString = cell.getRichStringCellValue ();
                                System.out.println ("String value: " + richTextString.getString ());

                                break;
                        }

                        default :
                        {

                                // types other than String and Numeric.
                                System.out.println ("Type not supported.");

                                break;
                        }
                }
                }
                }
                }
                catch (IOException e)
                {
                e.printStackTrace ();
                }
    return 0;
}

/**
* The main executable method to test displayFromExcel method.
*
* @param args
*/
}
